﻿using System;
using System.ComponentModel;
using System.ServiceModel;
using System.ServiceModel.Channels;

namespace FinMkts.Prices.ClientService
{
    [ServiceContract]
    public interface INotification
    {
        [OperationContract(IsOneWay = true, AsyncPattern = true, Action = NotificationData.NotificationAction)]
        IAsyncResult BeginNotify(Message message, AsyncCallback callback, object state);
        void EndNotify(IAsyncResult result);
    }

    [ServiceContract(CallbackContract = typeof(INotification))]
    public interface IPublishSubscribe
    {
        /// <summary>
        /// Start receiving notifications for a topic
        /// </summary>
        /// <param name="topic"></param>
        [OperationContract(IsOneWay = true)]
        void Subscribe(string topic);

        /// <summary>
        /// Stop receiving notifications for a topic
        /// </summary>
        /// <param name="topic"></param>
        [OperationContract(IsOneWay = true)]
        void Unsubscribe(string topic);

        /// <summary>
        /// Publish some content for a topic
        /// </summary>
        [OperationContract(IsOneWay = true)]
        void Publish(string topic, string content); //TODO: is this needed on this interface?
    }

    [MessageContract]
    public class NotificationData
    {
        public const string NotificationAction = "http://finmkts.com/notification";

        [MessageBodyMember]
        public string Topic { get; set; }

        [MessageBodyMember]
        public string Content { get; set; }
    }
}